package com.cbgolf.oa.activity.message;

import android.os.Bundle;
import android.support.annotation.Nullable;
import com.cbgolf.oa.R;
import com.cbgolf.oa.base.BaseActivity;
import com.cbgolf.oa.contract.IMessageCenterContract.IMessageCenterPresenter;
import com.cbgolf.oa.contract.IMessageCenterContract.IMessageCenterView;
import com.cbgolf.oa.contract.IMessageCenterContract.IMessageCenterWaiter;
import com.cbgolf.oa.event.EventMsg;
import com.cbgolf.oa.presenter.MessageCenterPresenterImp;
import com.cbgolf.oa.util.DataUtil;
import com.cbgolf.oa.views.MessageCenterViewImp;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 消息中心
 *
 * @author lq
 */
public class MessageCenterActivity extends BaseActivity implements IMessageCenterWaiter {

  /**
   * presenter
   */
  private IMessageCenterPresenter presenter;
  private IMessageCenterView view;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.a_message_center);
  }

  @Override
  protected void findViews() {
    EventBus.getDefault().register(this);
    view = new MessageCenterViewImp(this, this);
    presenter = new MessageCenterPresenterImp(view);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
  }

  @Override
  protected void loadData() {
    presenter.requestData(DataUtil.INITDATA);

  }

  @Subscribe(threadMode = ThreadMode.MAIN)
  public void requestOver(EventMsg event) {
    view.requestOver(event);
  }

  @Override
  public String getActivityTitle() {
    return "消息中心";
  }

  @Override
  public void back() {
    finish();
  }

  @Override
  public void readMsg(String id) {
    presenter.readMsg(id);
  }

  @Override
  public void onLoadmore() {
    presenter.requestData(DataUtil.LOADMORE);
  }

  @Override
  public void onRefresh() {
    presenter.requestData(DataUtil.REFRESH);
  }
}
